 /*
  *@(#)SiteConfig.java		8 Sept. 2000
  *
  * Copyright: MetaPlus Inc & Inquiry Management Systems Ltd.  2000
  *
  * This software is the proprietary information of MetaPlus Inc & 
  * Inquiry Management Systems Ltd.  
  * Use is subject to license terms.
  */
package com.ims.iaa;

/**
  * Demonstrate how to add requests directly to the Request Control Center 
  * without using database. It construct <code>LocalRequest</code> objects with 
  * nessesary data, then call the service provided by the "Request Control
  * Center" to add requests into the center.
  * <P>
  * Sample code:
  * <BLOCKQUOTE><PRE>
  * 	//get the handle of "Request Control Center"
  * 	RequestCtl reqCenter = IaaUtil.getRequestCenter("localhost",1099);
  * 	//start construct the LocalRequest object
  * 	LocalRequest lReq =	new LocalRequest(<cr>
  *                          "http://www.yahoo.com/",5);
  * 	//print out to check if the LocalRequest construct correctly
  * 	System.out.println(lReq);
  * 	//add the request object to the Center
  * 	try  {
  * 	    	reqCenter.addAdTrackRequest(lReq);
  * 	} catch  (java.rmi.RemoteException e)  {
  * 	    	System.out.println(<cr>
  * 	                  "Communication with Request Center error" + e);			
  * 	}
  * </PRE></BLOCKQUOTE>  
  *
  * @see LocalRequest#LocalRequest(String, int)
  * @see RequestCtlImpl#addAdTrackRequest  
  * 
  * @author Anthony Zhang
  *
  * @version 1.00, 25 Sept. 2000
  *
  */
public class SiteConfig {

	static String argString;

	/**
	  * Add search request directly into the "Request Control Center".
	  * <p><code>java com.ims.SiteConfig   serverName port searchURL</code></p>
	  * <p>The first command line parameter <code>serverName</code> is the server 
	  * host name or IP address, default is Localhost; the <code>port</code> 
	  * is the port number of server rmiregistry port, default is 1099; and the 
	  * <code> searchURL</code> is the URL scheduled to be searched such as
	  * "http://www.yahoo.com" or "file:\\\D:\TEMP\test.html". The server will take the default depth 5.</p>
	  *
	  */
	public static void main( String[] args ) {
//++***********************Add by ShengMeng Bai at 2004-07-27
		// we need the properties file loaded first
		try  {
			Class.forName("com.ims.iaa.IaaDebug");
		} catch (Exception e)  {
		}
//--***********************Add by ShengMeng Bai at 2004-07-27
		String serverName = "localhost";
		int serverPort = 1099;
		
		switch ( args.length ) {
		case 3 :
				argString = args[2];
//delete by ShengMeng Bai at 2004-07-27
//				break;//do not handle other two paramters.
		case 2 :
			try  { // try to get serverPort from command line
				serverPort = Integer.parseInt( args [1] );
			}catch (Exception e ) {
				usageInfo();
				return;
			}		
		case 1:
			try  { // try to get serverName from command line
				serverName = args [0];
			}catch (Exception e ) {
				usageInfo();
				return;
			}
			break;
		case 0: 
			break;
		default:
			usageInfo();
			
		}
		//++ Added by ShengMeng Bai at 2004-10-04
		serverName = IaaDebug.ServerHost;
		serverPort = IaaDebug.ServerPort;
		//-- Added by ShengMeng Bai at 2004-10-04
		RequestCtl reqCenter = IaaUtil.getRequestCenter(serverName,serverPort);	
		if ( reqCenter == null) {
		    IaaUtil.log( "Can not connect to Request Center" );		
			return;
		}

	    IaaUtil.log( "Begin add request to the Request Center" );		
		try  {
			if (argString != null)  {
				LocalRequest lReq =	new LocalRequest(argString, 5);
				lReq.setUserAgentObject(UserAgentAux.getInstance("Mozilla/4.0 (compatible; MSIE 5.0;Windows NT; DigExt)"));
				reqCenter.addAdTrackRequest(lReq);
			} else  {
				LocalRequest lReq =	new LocalRequest("http://www.giftonline.com/",5);
				lReq.setUserAgentObject(UserAgentAux.getInstance("Mozilla/4.0 (compatible; MSIE 5.0;Windows NT; DigExt)"));
				for (int i=1; i <15; i++)reqCenter.addAdTrackRequest(lReq);
			}
		} catch  (Exception e)  {
		    	IaaUtil.log( "Communication with Request Center error" + e);			
		}		
		System.exit(0);
	}

	private static void usageInfo() {		
		    IaaUtil.log( "usage: SiteConfig servername port " );
		    IaaUtil.log( "	 servername: server host name or IP address," 
		    	+ " default is Localhost " );
		    IaaUtil.log( "        port: port number of server rmiregistry port," 
		    	+ " default is 1099 " );		   		    
		    return;
	}

}		